package com.dc.project.controller.manage;

import com.dc.project.constant.ControllerConstant;
import com.dc.project.entity.dto.TemplateDetailAttachmentFieldDto;
import com.dc.project.entity.map.TemplateDetailAttachmentFieldMapVo;
import com.dc.project.entity.query.TemplateDetailAttachmentFieldQuery;
import com.dc.project.entity.vo.TemplateDetailAttachmentFieldVo;
import com.dc.project.service.TemplateDetailAttachmentFieldService;
import com.own.aop.operation.LogOperationModuleAop;
import com.own.aop.permission.PermissionModule;
import com.own.component.common.base.controller.BaseController;
import com.own.component.common.model.PageModel;
import com.own.component.common.model.R;
import com.own.component.common.model.ResultModel;
import com.own.component.store.core.confirm.aop.ConfirmAop;
import com.own.constant.ConstantApiPrefix;
import com.own.constant.ConstantBeanSuffix;
import com.own.util.list.TreeNode;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * ManageTemplateDetailAttachmentFieldController
 *
 * @author chenxueli
 * @date 2025-03-19 13:23:08
 */
@Slf4j
@Tag(name = "模板详情附件字段" + ConstantBeanSuffix.CONTROLLER)
@RestController
@LogOperationModuleAop("模板详情附件字段")
@PermissionModule("template-detail-attachment-field")
@RequestMapping(ConstantApiPrefix.BASE_API_V1_PREFIX + ControllerConstant.PREFIX_MANAGE_API + "template/detail/attachment/field")
public class ManageTemplateDetailAttachmentFieldController extends BaseController {

    @Resource
    private TemplateDetailAttachmentFieldService templateDetailAttachmentFieldService;

    @Operation(summary = "查询所有信息")
    @PostMapping("/all")
    public ResultModel<List<TemplateDetailAttachmentFieldVo>> all(
            @RequestBody TemplateDetailAttachmentFieldQuery query
    ) {
        var list = templateDetailAttachmentFieldService.all(query);
        return R.success(list);
    }

    @Operation(summary = "查询字段树")
    @PostMapping("/tree")
    public ResultModel<List<TreeNode<TemplateDetailAttachmentFieldMapVo>>> tree(
            @RequestBody TemplateDetailAttachmentFieldQuery query
    ) {
        var list = templateDetailAttachmentFieldService.tree(query);
        return R.success(list);
    }

    @Operation(summary = "分页查询信息")
    @PostMapping("/page")
    public ResultModel<PageModel<TemplateDetailAttachmentFieldVo>> page(
            @RequestBody TemplateDetailAttachmentFieldQuery query
    ) {
        var pageModel = templateDetailAttachmentFieldService.page(query);
        return R.success(pageModel);
    }

    @Operation(summary = "map查询信息")
    @PostMapping("/map")
    public ResultModel<List<TemplateDetailAttachmentFieldMapVo>> map(
            @RequestBody TemplateDetailAttachmentFieldQuery query
    ) {
        var list = templateDetailAttachmentFieldService.map(query);
        return R.success(list);
    }

    @Operation(summary = "添加信息")
    @PostMapping("/")
    public ResultModel<TemplateDetailAttachmentFieldVo> add(
            @Validated @RequestBody TemplateDetailAttachmentFieldDto dto
    ) {
        dto.check();
        var updateModel = templateDetailAttachmentFieldService.add(dto.toBo());
        return R.success(updateModel);
    }

    @Operation(summary = "修改信息")
    @PutMapping("/{templateDetailAttachmentFieldId}")
    public ResultModel<TemplateDetailAttachmentFieldVo> update(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentFieldId,
            @Validated @RequestBody TemplateDetailAttachmentFieldDto dto
    ) {
        dto.check();
        var updateModel = templateDetailAttachmentFieldService.update(templateDetailAttachmentFieldId, dto.toBo());
        return R.success(updateModel);
    }

    @ConfirmAop(message = "确认删除该项目？（注意：删除之后无法找回数据，且该项目所有资料会被删除）")
    @Operation(summary = "删除信息")
    @DeleteMapping("/{templateDetailAttachmentFieldId}")
    public ResultModel<Boolean> delete(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentFieldId
    ) {
        var updateModel = templateDetailAttachmentFieldService.delete(templateDetailAttachmentFieldId);
        return R.success(updateModel);
    }

    @Operation(summary = "根据id获取信息")
    @GetMapping("/{templateDetailAttachmentFieldId}")
    public ResultModel<TemplateDetailAttachmentFieldVo> getById(
            @Parameter(description = "主键id", required = true) @PathVariable Long templateDetailAttachmentFieldId
    ) {
        var vo = templateDetailAttachmentFieldService.getById(templateDetailAttachmentFieldId);
        return R.success(vo);
    }

}
